package crawler;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import javax.swing.text.AbstractDocument.BranchElement;

import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.xerces.internal.impl.xs.identity.Selector.Matcher;

import sun.misc.Regexp;
import sun.util.logging.resources.logging;
import weibo4j.Friendships;
import weibo4j.Timeline;
import weibo4j.examples.oauth2.Log;
import weibo4j.model.Paging;
import weibo4j.model.Status;
import weibo4j.model.StatusWapper;
import weibo4j.model.User;
import weibo4j.model.UserWapper;
import weibo4j.model.WeiboException;
import weibo4j.org.json.JSONObject;


/*
 * 这个类用来爬去微博数据
 * 
 * 输出1
 * 		关心的用户，及用户之间的关系
 * 		以JSON文件输出
 * 
 */
public class WeiboCrawler {
	/*
	 * 获取个人文集
	 * num为微博条数
	 */
	public List<String> getCorpusByName(String screenName, int num){
		return null;
	}
	
	/*
	 * 通过TD-IDT方法获取关键词
	 */
	public List<String> getKeyWords(List<String> corpus){
		return null;
	}
	
	@SuppressWarnings("deprecation")
	public static void saveJSON() throws IOException{
		Map<String, Object> map = new HashMap();
		
		List<Map<String, Object>> nodeList = new ArrayList<Map<String, Object>>();
		Map<String, Object> node;
		
		Date date = new Date();
		
		node = new HashMap<String, Object>();
		node.put("name", "fuck1");
		node.put("group", new Integer(1));
//		node.put("date", (new Date()).toString());
		nodeList.add(node);
		
		node = new HashMap<String, Object>();
		node.put("name", "fuck2");
		node.put("group", new Integer(2));
		date.setHours(2);
//		node.put("date", date.toString());
		nodeList.add(node);
		
		node = new HashMap<String, Object>();
		node.put("name", "fuck3");
		node.put("group", new Integer(2));
		date.setHours(3);
//		node.put("date", date.toString());
		nodeList.add(node);
		
		node = new HashMap<String, Object>();
		node.put("name", "fuck4");
		node.put("group", new Integer(1));
		date.setHours(4);
//		node.put("date", date.toString());
		nodeList.add(node);
		
		map.put("nodes", nodeList);
		
		List<Map<String, Integer>> linkList = new ArrayList<Map<String, Integer>>();
		Map<String, Integer> link;
		
		link = new HashMap<String, Integer>();
		link.put("source", 1);
		link.put("target", 0);
		link.put("value", 1);
		linkList.add(link);
		
		link = new HashMap<String, Integer>();
		link.put("source", 1);
		link.put("target", 3);
		link.put("value", 1);
		linkList.add(link);
		
		link = new HashMap<String, Integer>();
		link.put("source", 1);
		link.put("target", 4);
		link.put("value", 1);
		linkList.add(link);
		
		link = new HashMap<String, Integer>();
		link.put("source", 1);
		link.put("target", 2);
		link.put("value", 1);
		linkList.add(link);
		
		map.put("links", linkList);
		
		JSONObject json = new JSONObject(map);
		FileOutputStream stream = new FileOutputStream("a.json");
		StringBuffer sb = new StringBuffer();
		sb.append(json.toString());
		stream.write(json.toString().getBytes());
		stream.close();
		
	}
	
	private static String my_access_token = "2.00utce3C8tFiCB7a1dc3ca40ZTPehB";

	public static void main(String[] args) throws IOException {
		saveJSON();
		System.out.println("fuck java");
	}
	
	private class Reactor{
		
		public String getOrigin(String statusStr){
			if ( statusStr.startsWith("//@") ){
				int startInd 	= statusStr.indexOf("//@");
				int endInd		= statusStr.indexOf(':', startInd);
				String originScrNm 	= statusStr.substring(startInd, endInd);
				return originScrNm;
			}
			return null;
		}
	}
}
